package com.example.zhish.layout_demo001;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewStub;
import android.widget.Button;

public class MainActivity extends Activity implements View.OnClickListener{

    private Button button1;
    private ViewStub viewStub;
    private boolean flag =true;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button1 = (Button) findViewById(R.id.button1);
        viewStub = (ViewStub) findViewById(R.id.stub1);
        button1.setOnClickListener(this);
        viewStub.inflate();

    }

    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.button1:

                if(flag){
                    viewStub.setVisibility(ViewStub.GONE);

                }else{
                    viewStub.setVisibility(ViewStub.VISIBLE);

                }
                flag = !flag;


                break;

        }

    }
}
